.class public Lorg/microemu/midp/media/audio/PCTonePlayer;
.super Lorg/microemu/midp/media/BasicPlayer;
.source "PCTonePlayer.java"

# interfaces
.implements Lorg/microemu/midp/media/RunnableInterface;


# instance fields
.field private pcToneControl:Lorg/microemu/midp/media/audio/PCToneControl;

.field private running:Z

.field private sequenceIndex:I

.field private toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;


# direct methods
.method public constructor <init>()V
    .locals 2

    .prologue
    .line 48
    invoke-direct {p0}, Lorg/microemu/midp/media/BasicPlayer;-><init>()V

    .line 51
    :try_start_0
    new-instance v1, Lorg/microemu/midp/media/audio/PCToneControl;

    invoke-direct {v1}, Lorg/microemu/midp/media/audio/PCToneControl;-><init>()V

    iput-object v1, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->pcToneControl:Lorg/microemu/midp/media/audio/PCToneControl;

    .line 53
    new-instance v1, Lorg/microemu/midp/media/audio/PCTimeBase;

    invoke-direct {v1}, Lorg/microemu/midp/media/audio/PCTimeBase;-><init>()V

    invoke-virtual {p0, v1}, Lorg/microemu/midp/media/audio/PCTonePlayer;->setTimeBase(Lorg/microemu/midp/media/TimeBase;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 59
    :goto_0
    return-void

    .line 55
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 57
    .local v0, e:Ljava/lang/Exception;
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    goto :goto_0
.end method

.method private getNext()B
    .locals 3

    .prologue
    .line 124
    iget-object v0, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->pcToneControl:Lorg/microemu/midp/media/audio/PCToneControl;

    iget-object v0, v0, Lorg/microemu/midp/media/audio/PCToneControl;->sequence:[B

    iget v1, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->sequenceIndex:I

    add-int/lit8 v2, v1, 0x1

    iput v2, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->sequenceIndex:I

    aget-byte v0, v0, v1

    return v0
.end method


# virtual methods
.method public close()V
    .locals 0

    .prologue
    .line 63
    return-void
.end method

.method public getContentType()Ljava/lang/String;
    .locals 1

    .prologue
    .line 67
    const/4 v0, 0x0

    return-object v0
.end method

.method public getControl(Ljava/lang/String;)Ljavax/microedition/media/Control;
    .locals 1
    .parameter "controlType"

    .prologue
    .line 97
    sget-object v0, Lorg/microemu/midp/media/audio/PCTonePlayer;->CONTROL_TYPE:Ljava/lang/String;

    invoke-virtual {p1, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 99
    iget-object v0, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->pcToneControl:Lorg/microemu/midp/media/audio/PCToneControl;

    .line 103
    :goto_0
    return-object v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

.method public getControls()[Ljavax/microedition/media/Control;
    .locals 1

    .prologue
    .line 109
    const/4 v0, 0x0

    return-object v0
.end method

.method public isRunning()Z
    .locals 1

    .prologue
    .line 114
    iget-boolean v0, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->running:Z

    return v0
.end method

.method public playBlock()V
    .locals 12
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    const/4 v11, -0x6

    .line 130
    invoke-direct {p0}, Lorg/microemu/midp/media/audio/PCTonePlayer;->getNext()B

    move-result v0

    .line 133
    .local v0, currentByte:B
    :goto_0
    iget v7, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->sequenceIndex:I

    iget-object v8, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->pcToneControl:Lorg/microemu/midp/media/audio/PCToneControl;

    iget-object v8, v8, Lorg/microemu/midp/media/audio/PCToneControl;->sequence:[B

    array-length v8, v8

    if-ge v7, v8, :cond_2

    invoke-direct {p0}, Lorg/microemu/midp/media/audio/PCTonePlayer;->getNext()B

    move-result v0

    if-eq v0, v11, :cond_2

    .line 135
    const/4 v7, -0x1

    if-ne v0, v7, :cond_0

    .line 137
    iget-object v7, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;

    invoke-virtual {v7}, Lorg/microemu/midp/media/audio/ToneInfo;->getSleepDelay()I

    move-result v7

    int-to-long v7, v7

    invoke-static {v7, v8}, Ljava/lang/Thread;->sleep(J)V

    goto :goto_0

    .line 140
    :cond_0
    const/4 v7, -0x7

    if-ne v0, v7, :cond_1

    .line 143
    invoke-direct {p0}, Lorg/microemu/midp/media/audio/PCTonePlayer;->getNext()B

    goto :goto_0

    .line 147
    :cond_1
    const/16 v7, 0x45

    sub-int v7, v0, v7

    int-to-double v3, v7

    .line 148
    .local v3, noteDelta:D
    const-wide/high16 v7, 0x4028

    div-double v5, v3, v7

    .line 149
    .local v5, power:D
    const-wide v7, 0x407b800000000000L

    const-wide/high16 v9, 0x4000

    invoke-static {v9, v10, v5, v6}, Ljava/lang/Math;->pow(DD)D

    move-result-wide v9

    mul-double v1, v7, v9

    .line 153
    .local v1, d_frequency:D
    iget-object v7, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;

    double-to-int v8, v1

    invoke-virtual {v7, v8}, Lorg/microemu/midp/media/audio/ToneInfo;->setFrequency(I)V

    .line 157
    iget-object v7, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;

    invoke-virtual {v7}, Lorg/microemu/midp/media/audio/ToneInfo;->getFrequency()I

    move-result v7

    iget-object v8, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;

    invoke-virtual {v8}, Lorg/microemu/midp/media/audio/ToneInfo;->getLengthOfTime()I

    move-result v8

    iget-object v9, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;

    invoke-virtual {v9}, Lorg/microemu/midp/media/audio/ToneInfo;->getVolume()I

    move-result v9

    invoke-static {v7, v8, v9}, Ljavax/microedition/media/Manager;->playTone(III)V

    .line 162
    iget-object v7, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;

    invoke-virtual {v7}, Lorg/microemu/midp/media/audio/ToneInfo;->getLengthOfTime()I

    move-result v7

    add-int/lit8 v7, v7, 0x14

    int-to-long v7, v7

    invoke-static {v7, v8}, Ljava/lang/Thread;->sleep(J)V

    goto :goto_0

    .line 166
    .end local v3           #noteDelta:D
    .end local v5           #power:D
    .end local v1           #d_frequency:D
    :cond_2
    if-ne v0, v11, :cond_3

    .line 169
    invoke-direct {p0}, Lorg/microemu/midp/media/audio/PCTonePlayer;->getNext()B

    .line 172
    :cond_3
    return-void
.end method

.method public run()V
    .locals 12

    .prologue
    .line 180
    const/4 v6, 0x0

    :try_start_0
    iput v6, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->sequenceIndex:I

    .line 182
    new-instance v6, Lorg/microemu/midp/media/audio/ToneInfo;

    invoke-direct {v6}, Lorg/microemu/midp/media/audio/ToneInfo;-><init>()V

    iput-object v6, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;

    .line 184
    const/4 v6, 0x1

    invoke-virtual {p0, v6}, Lorg/microemu/midp/media/audio/PCTonePlayer;->setRunning(Z)V

    .line 187
    :cond_0
    :goto_0
    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCTonePlayer;->isRunning()Z

    move-result v6

    if-eqz v6, :cond_6

    iget v6, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->sequenceIndex:I

    iget-object v7, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->pcToneControl:Lorg/microemu/midp/media/audio/PCToneControl;

    iget-object v7, v7, Lorg/microemu/midp/media/audio/PCToneControl;->sequence:[B

    array-length v7, v7

    if-ge v6, v7, :cond_6

    .line 189
    invoke-direct {p0}, Lorg/microemu/midp/media/audio/PCTonePlayer;->getNext()B

    move-result v0

    .line 190
    .local v0, currentControlCommand:B
    const/4 v6, -0x2

    if-ne v0, v6, :cond_1

    .line 192
    invoke-direct {p0}, Lorg/microemu/midp/media/audio/PCTonePlayer;->getNext()B

    goto :goto_0

    .line 240
    .end local v0           #currentControlCommand:B
    :catch_0
    move-exception v6

    .line 244
    :goto_1
    return-void

    .line 197
    .restart local v0       #currentControlCommand:B
    :cond_1
    const/4 v6, -0x8

    if-ne v0, v6, :cond_2

    .line 199
    iget-object v6, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;

    invoke-direct {p0}, Lorg/microemu/midp/media/audio/PCTonePlayer;->getNext()B

    move-result v7

    invoke-virtual {v6, v7}, Lorg/microemu/midp/media/audio/ToneInfo;->setVolume(I)V

    goto :goto_0

    .line 203
    :cond_2
    const/4 v6, -0x3

    if-ne v0, v6, :cond_3

    .line 207
    invoke-direct {p0}, Lorg/microemu/midp/media/audio/PCTonePlayer;->getNext()B

    move-result v5

    .line 209
    .local v5, tempo:B
    const-wide/high16 v3, 0x4050

    .line 210
    .local v3, resolutionDenominator:D
    const-wide/high16 v6, 0x406e

    const-wide/high16 v8, 0x3ff0

    div-double/2addr v8, v3

    int-to-double v10, v5

    mul-double/2addr v8, v10

    div-double v1, v6, v8

    .line 211
    .local v1, durationOfNote:D
    iget-object v6, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;

    double-to-int v7, v1

    div-int/lit8 v7, v7, 0x10

    invoke-virtual {v6, v7}, Lorg/microemu/midp/media/audio/ToneInfo;->setLengthOfTime(I)V

    goto :goto_0

    .line 215
    .end local v5           #tempo:B
    .end local v3           #resolutionDenominator:D
    .end local v1           #durationOfNote:D
    :cond_3
    const/4 v6, -0x1

    if-ne v0, v6, :cond_4

    .line 217
    iget-object v6, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;

    invoke-direct {p0}, Lorg/microemu/midp/media/audio/PCTonePlayer;->getNext()B

    move-result v7

    invoke-virtual {v6, v7}, Lorg/microemu/midp/media/audio/ToneInfo;->setSleepDelay(I)V

    .line 219
    iget-object v6, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->toneInfo:Lorg/microemu/midp/media/audio/ToneInfo;

    invoke-virtual {v6}, Lorg/microemu/midp/media/audio/ToneInfo;->getSleepDelay()I

    move-result v6

    int-to-long v6, v6

    invoke-static {v6, v7}, Ljava/lang/Thread;->sleep(J)V

    goto :goto_0

    .line 222
    :cond_4
    const/4 v6, -0x7

    if-eq v0, v6, :cond_5

    const/4 v6, -0x5

    if-ne v0, v6, :cond_0

    .line 226
    :cond_5
    invoke-virtual {p0}, Lorg/microemu/midp/media/audio/PCTonePlayer;->playBlock()V

    goto :goto_0

    .line 237
    .end local v0           #currentControlCommand:B
    :cond_6
    invoke-super {p0}, Lorg/microemu/midp/media/BasicPlayer;->stop()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_1
.end method

.method public setRunning(Z)V
    .locals 0
    .parameter "running"

    .prologue
    .line 119
    iput-boolean p1, p0, Lorg/microemu/midp/media/audio/PCTonePlayer;->running:Z

    .line 120
    return-void
.end method

.method public declared-synchronized start()V
    .locals 2
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/media/MediaException;
        }
    .end annotation

    .prologue
    .line 74
    monitor-enter p0

    :try_start_0
    new-instance v1, Ljava/lang/Thread;

    invoke-direct {v1, p0}, Ljava/lang/Thread;-><init>(Ljava/lang/Runnable;)V

    invoke-virtual {v1}, Ljava/lang/Thread;->start()V

    .line 75
    invoke-super {p0}, Lorg/microemu/midp/media/BasicPlayer;->start()V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 81
    :goto_0
    monitor-exit p0

    return-void

    .line 77
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 79
    .local v0, e:Ljava/lang/Exception;
    :try_start_1
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    goto :goto_0

    .line 74
    .end local v0           #e:Ljava/lang/Exception;
    :catchall_0
    move-exception v1

    monitor-exit p0

    throw v1
.end method

.method public declared-synchronized stop()V
    .locals 2
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/media/MediaException;
        }
    .end annotation

    .prologue
    .line 87
    monitor-enter p0

    const/4 v1, 0x0

    :try_start_0
    invoke-virtual {p0, v1}, Lorg/microemu/midp/media/audio/PCTonePlayer;->setRunning(Z)V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 93
    :goto_0
    monitor-exit p0

    return-void

    .line 89
    :catch_0
    move-exception v0

    .line 91
    .local v0, e:Ljava/lang/Exception;
    :try_start_1
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    goto :goto_0

    .line 87
    .end local v0           #e:Ljava/lang/Exception;
    :catchall_0
    move-exception v1

    monitor-exit p0

    throw v1
.end method
